<?php
function a(){
 echo  123;
}

echo '<a href='.a().'>测试</a>';
$a=1;

?>

<script>
 var a="<?php echo $a ?>";
 var img =new Image();
 img.src='img/'+'<?php echo $a ?>'
 console.log(img);
</script>


